# coding=utf-8
import sys
import os
#import configparser

base_path = os.getcwd()
sys.path.append(base_path)
#print(base_path)
import requests
import json


class BaseRequest:

    def send_post(self, url, json_data, header=None):
        '''
        发送post请求
        '''

        response = requests.post(url=url, json=json_data, headers=header)

        res = response.text
        return res

    def send_get(self, url, parameters, header=None):
        '''
        发送post请求
        '''

        response = requests.get(url=url, params=parameters, headers=header)

        res = response.text
        return res

    def run_main(self, method, url, json_params, header=None):
        '''
        执行方法，传递method、url、data参数
        '''
        if method == 'get':
            res = self.send_get(url, json_params, header)
        else:
            res = self.send_post(url, json_params, header)
        try:
            res = json.loads(res)
        except:
            print("这个结果是一个text")
        #print("--->", res)
        return res


my_request = BaseRequest()
if __name__ == "__main__":
    request = BaseRequest()

    request.run_main('post', "http://apiygtpm.yong-gang.cn:8260",{"userName": "005087", "password": "123456"})
